package org.tp8.sampleapp.jaxb.paging.adapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.springframework.data.domain.Page;
import org.tp8.sampleapp.jaxb.paging.dto.JaxbPage;
import org.tp8.sampleapp.jaxb.paging.dto.PageResponse;

/**
 * The Class PageAdapter.
 */
@SuppressWarnings("rawtypes")
public class PageAdapter extends XmlAdapter<JaxbPage, Page> {

	/* (non-Javadoc)
	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
	 */
	public Page unmarshal(final JaxbPage pojo) throws Exception {
		return new PageResponse(pojo);
	}

	/* (non-Javadoc)
	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
	 */
	public JaxbPage marshal(Page page) throws Exception {
		JaxbPage pojo = new JaxbPage();
		pojo.setContent(page.getContent());
		pojo.setNumber(page.getNumber());
		pojo.setNumberOfElements(page.getNumberOfElements());
		pojo.setSize(page.getSize());
		pojo.setTotalElements(page.getTotalElements());
		pojo.setTotalPages(page.getTotalPages());
		return pojo;
	}

}